<?php
require_once ('/home/n02586916/WWW/fall2012/fall2012/Final/inc/functions.php');

class Transactions
{
	static function GetAll()
	{
		$conn = GetConnection();
		return $conn->query('SELECT * FROM Transactions');
	}
	
	static function Get($id)
	{
		$conn = GetConnection();
		$results = $conn->query("SELECT * FROM Transactions WHERE id=$id");
		$row = $results->fetch_assoc();
		$conn->close();
		return $row;
	}

	static function Insert()
	{
	}
	
	static function Update($row)
	{
		$conn = GetConnection();
		$row2 = EscapeRow($row, $conn);
		$sql = 	"UPDATE Transactions "
			.	"Set id='$row2[id]',Completed='$row2[Completed]',Underprocess='$row2[Underprocess]' "
			.	"WHERE id=$row2[id] ";
		echo $sql;
		$conn->query($sql);
		$error = $conn->error;
		$conn->close();
		
		return $error != '' ? array('Server Error' => $error) : true;		
	}
	
	static function Delete()
	{
	}
	
	static function Validate($row)
	{
		$results = array();
		if(!is_numeric($row['Keyword_id'])) $results['Keyword_id'] = 'Keyword id needs to be a number';
		if(empty($row['Keyword_id'])) $results['Keyword_id'] = 'Keyword is required';
		if(empty($row['FirstName'])) $results['FirstName'] = 'FirstName is required';
		if(empty($row['LastName'])) $results['LastName'] = 'LastName is required';
		
		return count($results) > 0 ? $results : true;
	}
}
